﻿package net.wangit.adm.group;

import net.wangit.Unit;
import net.wangit.context.ActionContext;
import net.wangit.support.UnitInterceptor;
import net.wangit.user.group.UserGroup;
import net.wangit.user.group.UserGroupFactory;
import net.wangit.util.Checker;
import net.wangit.view.unit.UnitComponent;

public class GroupRelationUI implements UnitInterceptor {

	public GroupRelationUI() {
	}

	public String intercept(ActionContext ac, Unit unit) throws Exception {
		String groupId = ac.getRequestParameter("groupid");
		if (Checker.isEmpty(groupId)) {
			return "";
		} else {
			UserGroup group = UserGroupFactory.getUserGroup(groupId);
			unit.setTitle((new StringBuilder(String
					.valueOf(((UnitComponent) unit).getTitle()))).append(" - ")
					.append(group.getName()).append("(").append(groupId)
					.append(")").toString());
			return unit.write(ac);
		}
	}
}
